/*===========================================================================+
 |   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
 |                         All rights reserved.                              |
 +===========================================================================+
 |  HISTORY                                                                  |
 +===========================================================================*/
package xxhci.oracle.apps.xxierp.PDSPSample.webui;

import java.io.Serializable;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageRadioButtonBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageRadioGroupBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;

import oracle.jbo.Row;

/**
 * Controller for ...
 */
public class RadioButtonCO extends OAControllerImpl
{
  public static final String RCS_ID="$Header$";
  public static final boolean RCS_ID_RECORDED =
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

  /**
   * Layout and page setup logic for a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
    
    
    
     OAMessageRadioButtonBean one =   
     (OAMessageRadioButtonBean)webBean.findChildRecursive("one"); //First Radio Button   
     one.setName("SelectOption");   
     one.setValue("one");     
      
     OAMessageRadioButtonBean two =   
     (OAMessageRadioButtonBean)webBean.findChildRecursive("two"); //Second Radio Button   
     two.setName("SelectOption");   
     two.setValue("two");  
     
       OAMessageRadioButtonBean three =   
     (OAMessageRadioButtonBean)webBean.findChildRecursive("three"); //Third Radio Button   
     three.setName("SelectOption");   
     three.setValue("three"); 
       OAMessageRadioButtonBean four =   
     (OAMessageRadioButtonBean)webBean.findChildRecursive("four"); //Fourth Radio Button   
     four.setName("SelectOption");   
     four.setValue("four");
     
      OAApplicationModule am = pageContext.getApplicationModule(webBean);
      // am.invokeMethod("createRadio");
      Serializable[] initParams = {"1"};
      am.invokeMethod("updateRadio", initParams);
      OAViewObject empVO = (OAViewObject)am.findViewObject("XxTestRadioVO1");
      Row row[] = empVO.getAllRowsInRange();
      
     if(row[0].getAttribute("Item")!=null)
     {
        OAMessageRadioGroupBean grp=(OAMessageRadioGroupBean) webBean.findChildRecursive("SelectOption");
        grp.
         OAMessageRadioButtonBean rdBtn=(OAMessageRadioButtonBean) webBean.findChildRecursive(row[0].getAttribute("Item").toString());
         rdBtn.setSelected(true);
     }
     else
     {
             OAMessageRadioButtonBean rdBtn=(OAMessageRadioButtonBean) webBean.findChildRecursive("one");
             rdBtn.setSelected(true);
    }
 

  }

  /**
   * Procedure to handle form submissions for form elements in
   * a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    
    OAApplicationModule am = pageContext.getApplicationModule(webBean);   
  
//You can then obtain the selected radio button in your processFormRequest() as follows:   
  
String radioGroupValue = pageContext.getParameter("SelectOption"); 
OAMessageTextInputBean txt=(OAMessageTextInputBean)webBean.findChildRecursive("Result");
txt.setValue(pageContext,radioGroupValue);


    am.invokeMethod("savePersonToDatabase");




  }

}
